package w4156.idog.server;

import java.util.HashMap;
import java.util.Map;

import javax.ejb.Stateful;
import javax.naming.InitialContext;
import w4156.idog.model.Card;

/**
 * Session Bean implementation class CardsManagerBean
 */
@Stateful(mappedName = "ejb/eBlackjack/CardsManagerSLSB")
public class CardsManagerBean implements CardsManagerBeanRemote {

	private Map<Integer, CardsBean> map;

	/**
	 * Default constructor.
	 */
	public CardsManagerBean() {
		init();
	}

	private void init() {
		map=new HashMap<Integer, CardsBean>();
	}

	public Card getcard(int cid) {
		try {
			if (map.containsKey(cid)) {
				CardsBean gamecard = map.get(cid);
				return gamecard.dealCard();
			} else {
				InitialContext context = new InitialContext();
				CardsBeanRemote gamecards = (CardsBeanRemote) context
						.lookup("ejb/eBlackjack/CardsSLSB");
				// CardsBean gamecards = new CardsBean ();
				gamecards.shuffle();
				return gamecards.dealCard();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public CardsBean getcards(int tableid) {
		// TODO Auto-generated method stub
		return null;
	}

}
